package cn.jilian.meta.handler.impl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.stereotype.Component;

import cn.jilian.meta.handler.CompGenerator;
import cn.jilian.meta.handler.GeneratorManager;
import cn.jilian.meta.handler.domain.Container;
import cn.jilian.meta.handler.domain.Grid;
import cn.jilian.meta.handler.domain.Model;
import cn.jilian.meta.handler.domain.PropertyGrid;
import cn.jilian.meta.handler.domain.SimpleRestJsonStore;
import cn.jilian.meta.handler.domain.TreeStore;
import cn.jilian.meta.handler.generators.BorderContainerGenerator;
import cn.jilian.meta.handler.generators.ProperyGridGenerator;
import cn.jilian.meta.handler.generators.SimpleGridGenerator;
import cn.jilian.meta.handler.generators.SimpleModelGenerator;
import cn.jilian.meta.handler.generators.SimpleRestJsonStoreGenerator;
import cn.jilian.meta.handler.generators.SimpleTreeStoreGenerator;

@Component
public class ExtjsGeneratorManager implements GeneratorManager {

	private Map<Class<?>,CompGenerator<?>> classMap;
	
	public ExtjsGeneratorManager() {
		this.classMap=new ConcurrentHashMap<>();
		this.classMap.put(Grid.class, new SimpleGridGenerator(this));
		this.classMap.put(Model.class, new SimpleModelGenerator(this));
		this.classMap.put(PropertyGrid.class, new ProperyGridGenerator(this));
		this.classMap.put(TreeStore.class, new SimpleTreeStoreGenerator(this));
		this.classMap.put(Container.class, new BorderContainerGenerator(this));
		this.classMap.put(SimpleRestJsonStore.class, new SimpleRestJsonStoreGenerator(this));
		
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public <T> CompGenerator<T> getGenerator(Class<? extends T> type) {
		return (CompGenerator<T>) classMap.get(type);
	}

}
